package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizComboFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizComboQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizComboVO;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceRelationUserFormVO;
import cn.sfrog.project.biz.admin.service.IBizComboService;
import cn.sfrog.project.biz.admin.service.IBizServiceUserService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "管理后台-套餐相关")
@RestController
@RequestMapping("/biz/combo")
public class BizComboController extends BaseController {
    @Resource
    private IBizComboService bizComboService;
    @Autowired
    private IBizServiceUserService bizServiceUserService;

    /**
     * 查询套餐列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:combo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizComboQueryVO queryVO) {
        startPage();
        List<BizComboVO> list = bizComboService.selectBizComboList(queryVO);
        return getDataTable(list);
    }

    /**
     * 导出套餐列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:combo:export')")
    @Log(title = "套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizComboQueryVO query) {
        List<BizComboVO> list = bizComboService.selectBizComboList(query);
        ExcelUtil<BizComboVO> util = new ExcelUtil<BizComboVO>(BizComboVO.class);
        util.exportExcel(response, list, "套餐数据");
    }

    /**
     * 获取套餐详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:combo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizComboService.selectBizComboById(id));
    }

    /**
     * 新增套餐
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:combo:add')")
    @Log(title = "套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizComboFormVO form) {
        return toAjax(bizComboService.insertBizCombo(form));
    }

    /**
     * 修改套餐
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:combo:edit')")
    @Log(title = "套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizComboFormVO form) {
        return toAjax(bizComboService.updateBizCombo(form));
    }

    /**
     * 删除套餐
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:combo:remove')")
    @Log(title = "套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizComboService.deleteBizComboByIds(ids));
    }

    /**
     * 更改状态套餐
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasPermi('biz:combo:changeStatus,biz:combo:changeStatusBatch')")
    @Log(title = "套餐", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizComboService.changeStatus(vo));
    }

    @ApiOperation("关联人员")
    @PreAuthorize("@ss.hasPermi('biz:combo:relationUser')")
    @Log(title = "服务", businessType = BusinessType.INSERT)
    @PostMapping("/relationUser")
    public AjaxResult relationUser(@RequestBody @Validated BizServiceRelationUserFormVO form){
        return AjaxResult.success(bizServiceUserService.relationUser(form));
    }
}
